package com.yby6.wxpay.controller;


import com.yby6.common.core.AjaxResult;
import com.yby6.common.enums.wxpay.OrderStatus;
import com.yby6.wxpay.domain.OrderInfo;
import com.yby6.wxpay.service.OrderInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 商品订单接口
 *
 * @author yang shuai
 * @date 2022/11/13
 */

@Api(tags = "商品订单管理")
@RestController
@RequestMapping("/api/order-info")
public class OrderInfoController {

    @Resource
    private OrderInfoService orderInfoService;

    @ApiOperation("订单列表")
    @GetMapping("/list")
    public AjaxResult list() {
        List<OrderInfo> list = orderInfoService.lambdaQuery().orderByDesc(OrderInfo::getCreateTime).list();
        return AjaxResult.success(list);
    }

    /**
     * 查询本地订单状态
     */
    @ApiOperation("查询本地订单状态")
    @GetMapping("/query-order-status/{orderNo}")
    public AjaxResult queryOrderStatus(@PathVariable String orderNo) {
        String orderStatus = orderInfoService.lambdaQuery().eq(OrderInfo::getOrderNo, (orderNo)).one().getOrderStatus();
        if (OrderStatus.SUCCESS.getType().equals(orderStatus)) {
            return AjaxResult.success("支付成功"); //支付成功
        }

        return AjaxResult.error(101, "支付中......");
    }


}
